//
//  XLAppLicenseViewController.m
//  Mine
//
//  Created by 于鹏 on 2017/8/30.
//  Copyright © 2017年 YIVIEW. All rights reserved.
//

#import "XLAppLicenseViewController.h"

//#import <XLBaseModule/XLRequestURLInfo.h>
//#import <PPNetworkHelper.h>
#import "PPNetworkHelper.h"
#import "XLRequestURLInfo.h"

@interface XLAppLicenseViewController ()<UIWebViewDelegate>
@property (nonatomic,strong) UIWebView *webView;
@end

@implementation XLAppLicenseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"软件许可协议";
    self.titleStr = @"软件许可使用协议";
}



- (void)initData {
    [super initData];
    
    NSString *str = self.titleStr;
    //url中含有中文字符转码
    CFStringRef finalTurnStr = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)str, NULL, NULL, kCFStringEncodingUTF8);
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setValue:(__bridge NSString *)finalTurnStr forKey:@"aggrementName"];
    [XLHTTPRequest getAgreementInfoWithParameters:parameters success:^(id responseObject) {
        if ([responseObject[@"status"] isEqualToString:@"1"]){
            
            NSURL *url = [NSURL URLWithString:[kDomain_BgImg stringByAppendingString:[NSString stringWithFormat:@"%@",responseObject[@"data"][@"agreementURL"]]]];
            NSURLRequest *request = [NSURLRequest requestWithURL:url];
            [self.webView loadRequest:request];
            
        }else{
//            [self exitLogin:responseObject[@"Msg"]];
            [self showErrorWithStatus:responseObject[@"info"]];

        }
        [self dismissHUD];
    } failure:^(NSError *error, NSString *info) {
        [self showErrorWithStatus:NetworkTimeout];

    }];
    
    
}

- (void)initInterface
{
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    self.webView.delegate = self;
    [self.view addSubview:self.webView];
}



- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [self showHUD];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    [self dismissHUD];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [self dismissHUD];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
